package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amap.api.services.core.PoiItem;
import com.sam.im.heiqun.R;
import com.sam.im.heiqun.uis.adapters.holder.NearLocationHolder;

import java.util.List;

/**
 * Created by wangguodong on 2017/1/8.
 * 通讯录使用
 */

public class NearLocationAdpter extends RecyclerView.Adapter<NearLocationHolder> {

    private Context context;
    private List<PoiItem> mPoiInfos;
    private NearListClickListener mItemClickListener;
    private int type = 0;//判断是否显示；0-不显示；1-显示;2-不显示
    private int showPosition = -1;

    public void setShowPosition(int position) {
        showPosition = position;
        notifyDataSetChanged();
    }

    public NearLocationAdpter(Context context, List<PoiItem> mPoiInfos) {
        this.context = context;
        this.mPoiInfos = mPoiInfos;
    }

    public NearLocationAdpter(Context context, List<PoiItem> mPoiInfos, int type) {
        this.context = context;
        this.mPoiInfos = mPoiInfos;
        this.type = type;
    }

    public NearLocationAdpter(Context context) {
        this.context = context;
    }

    public void refresh(List<PoiItem> mPoiInfos) {
        this.mPoiInfos = mPoiInfos;
        notifyDataSetChanged();
    }

    public interface NearListClickListener {
        void onSelectClick(View view, int position);
    }

    public void setItemClickListener(NearListClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }

    @Override
    public NearLocationHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.nearby_item_layout, parent, false);
        return new NearLocationHolder(view, mItemClickListener);
    }

    @Override
    public void onBindViewHolder(NearLocationHolder holder, int position) {
        PoiItem poiItem = mPoiInfos.get(position);
        Log.i("info","适配器中 item== "+poiItem.getTitle());
        /*if (position!=1){*/
            holder.address.setText(poiItem.getTitle());
            holder.addr.setText(poiItem.getProvinceName()+poiItem.getCityName()+poiItem.getAdName()+poiItem.getSnippet());
       /* }else {
            holder.address.setText(poiItem.getAdName()+poiItem.getTitle());
        }*/
        if (showPosition == position) {
            holder.select_address.setVisibility(View.VISIBLE);
        } else {
            holder.select_address.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return mPoiInfos != null ? mPoiInfos.size() : 0;
    }
}